<?php
/**
 * @copyright Arthur Beer
 * @package core
 *
 * @copyright TinyWEB CMS
 * @link http://tinywebcms.ru
 * @link http://cms.vingrad.ru
 * @version SVN: $Id$ 
 */
 
/**
 * Env
 */
final class Env extends Object 
{
	private static $params;

    private function __construct() {}
    
    public static function get($name, $default = null)
    {
    	return self::ifgetor($name, $_GET, $default);
    }
    
    public static function post($name, $default = null)
    {
    	return self::ifgetor($name, $_POST, $default);
    }
    
    public static function server($name, $default = null)
    {
    	return self::ifgetor($name, $_SERVER, $default);
    }
    
    public static function request($name, $default = null)
    {
    	return self::ifgetor($name, $_REQUEST, $default);
    }
    
    public static function cookie($name, $default = null, $write = false)
    {
    	return self::ifgetor($name, $_COOKIE, $default);
    }
    
    public static function setCookie($name, $value = null, $expires = 15552000, $domain = null, $path = '/', $secured = false)
    {
        setcookie($name, $value, time() + $expires, $path, $domain, $secured);
    }
    
    public static function session($name, $default = null)
    {
    	return self::ifgetor($name, $_SESSION, $default);
    }
    
    public static function files($name, $default = null)
    {
    	return self::ifgetor($name, $_FILES, $default);
    }
    
    public static function ifgetor($name, $array, $default = null) {
    	if(array_key_exists($name, $array)) {
    		return $array[$name];
    	}
    	
    	return $default;
    }
    
    public static function getParam($name = null, $default = null)
    {
    	if($name) {
    		if(!self::$params) {
    			self::$params = explode('/', Env::server('REQUEST_URI', Env::server('HTTP_X_URI')));
    		}
    		
    		return isset(self::$params[$name]) ? self::$params[$name] : $default;
    	}
    	
    	return self::$params;
    }
    
    public static function setParam($name, $value)
    {
    	self::$params[$name] = $value;
    }
}

class Request
{
    public static function normalize()
    {
        if(array_key_exists('HTTP_X_URI', $_SERVER)) {
            $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_URI'];
        }
    }
}

/**
 * Tab: 4 spaces
 * Encoding: utf-8
 */
?>